package model

import "encoding/xml"

/**
 * @Description
 * @Author lulili
 * @Date 2024/10/22 15:32
 */

type (
	CmdType struct {
		CmdType string `xml:"CmdType"`
	}

	DeviceID struct {
		DeviceID string `xml:"DeviceID"`
	}

	SN struct {
		SN string `xml:"SN"`
	}
)
type DeviceCatalogResponse struct {
	Name xml.Name `xml:"Response"`
	CmdType
	SN
	DeviceID
	SunNum        string     `xml:"SunNum"`
	DeviceListNum string     `xml:"Num,attr"`
	DeviceList    DeviceList `xml:"DeviceList"`
}

type DeviceList struct {
	Name  xml.Name      `xml:"DeviceList"`
	Items []CatalogItem `xml:"Item"`
}

type CatalogItem struct {
	XmlName xml.Name `xml:"Item"`
	DeviceID
	Name         string `xml:"Name"`
	Manufacturer string `xml:"Manufacturer"`
	Model        string `xml:"Model"`
	Owner        string `xml:"Owner"`
	CivilCode    string `xml:"CivilCode"`
	Address      string `xml:"Address"`
	Parental     string `xml:"Parental"`
	ParentID     string `xml:"ParentID"`
	SafetyWay    string `xml:"SafetyWay"`
	RegisterWay  string `xml:"RegisterWay"`
	Secrecy      string `xml:"Secrecy"`
	Status       string `xml:"Status"`
}

// xml解析心跳包结构
type Keepalive struct {
	CmdType  string `xml:"CmdType"`
	SN       int    `xml:"SN"`
	DeviceID string `xml:"DeviceID"`
	Status   string `xml:"Status"`
	Info     string `xml:"Info"`
}

func (i CatalogItem) ConvertToChannel() Channel {
	c := NewChannelMust(i.DeviceID.DeviceID)
	c.Name = i.Name
	c.Manufacturer = i.Manufacturer
	c.Model = i.Model
	c.Owner = i.Owner
	c.CivilCode = i.CivilCode
	c.Address = i.Address
	c.Parental = i.Parental
	c.ParentID = i.ParentID
	c.SafetyWay = i.SafetyWay
	c.RegisterWay = i.RegisterWay
	c.Secrecy = i.Secrecy
	c.Status = i.Status
	return c
}
